﻿using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XiaoYuStock.Core;
using System.Configuration;
using XiaoYuStock.AppService;

namespace XiaoYuStock.Hosts.Jobs
{
    public class CurrentSeasonJob : IJob
    {
        /// <summary>
        /// 执行任务
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            LogHelper.Info("获取当季任务开始");

            try
            {
                var year = DateTime.Now.Year;
                var season = 1;
                if (ConfigurationManager.AppSettings["Season"] != null)
                {
                    var currentSeason = ConfigurationManager.AppSettings["Season"]?.ToString().Split(',');
                    year =Convert.ToInt32(currentSeason[0]);
                    season= Convert.ToInt32(currentSeason[1]);
                }
                DataMapping.GetSharesHistoryData(year, season);
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取当季任务异常" + ex.ToString() + ex.StackTrace);
                if (ex.InnerException != null)
                {
                    LogHelper.Error("内部错误" + ex.InnerException.ToString());
                }
            }

            LogHelper.Info("获取当季任务完成");
        }
    }
}
